home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / xw2.000 / xw2 / xw / csource / makemfx / makemfxparser.y < prev    next >
Encoding:
Lex Description  |  1995-03-02  |  19.7 KB  |  558 lines

  1. %{
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <ctype.h>
  8.  
  9. int yyerror(char*s){ printf(s); return(0); }
  10. void create_c_files(void);
  11. int write_c_files(char *s, char *pgm);
  12.  
  13. int struct_defined=0;
  14.  
  15. FILE *fp_xbc;
  16. FILE *fp_xbm;
  17. FILE *fp_wdw;
  18. FILE *fp_trl;
  19.  
  20. FILE *fp_wmfx;
  21. FILE *fp_rmfx;
  22. FILE *fp_dmfx;
  23. FILE *fp_dwdw;
  24.  
  25. char pgmname[100];
  26. char c_struct_name[100];
  27. char c_var_name[100];
  28. int obj=0;
  29.  
  30. int wdwnr=0;
  31.  
  32. %}
  33.  
  34. %union { char sstr[100]; int val; };
  35.  
  36. %token <sstr>  NUMBER
  37. %token <sstr>  NAME
  38. %token <sstr>  INT
  39. %token <sstr>  DOUBLE
  40. %token <sstr>  STRING
  41. %token <sstr>  SHORT
  42. %token <sstr>  TYPEDEF
  43. %token <sstr>  STRUCT
  44. %token <sstr>  EXTERN
  45. %token <sstr>  DEFINE
  46. %token <sstr>  IFDEF
  47. %token <sstr>  ENDIF
  48. %token <sstr>  PGMNAME
  49. %token <sstr>  MFXINIT
  50. %type  <sstr>  v
  51.  
  52. %left  ']'
  53. %right  '['
  54. %left  '}'
  55. %right  '{'
  56. %left   ';'
  57.  
  58. %left  HIPREC
  59.  
  60. %%
  61.  
  62.  
  63. input:   /* empty */
  64.        | input v { }
  65.        ;
  66. v:  TYPEDEF STRUCT '{'            {
  67.     printf("PARSING typedef struct {\n");
  68.     create_c_files();
  69.     }
  70.   | '}' NAME ';' {
  71.     printf("} PARSED: %s\n",$2);
  72.     sprintf(c_struct_name,$2);
  73.     }
  74.   | EXTERN NAME NAME ';'          {
  75.     sprintf(c_var_name,$3);
  76.     printf("\nJust found \"extern %s %s\"; I will use that declaration.\n",
  77.       $2,$3);
  78.     }
  79.   | DEFINE NAME NAME            { }
  80.   | DEFINE NAME NUMBER          { }
  81.   | DEFINE PGMNAME NAME           {
  82.     char sstr[100];
  83.     int ii;
  84.     strcpy(pgmname,$3);
  85.     printf("\nI think \"%s\" is the program you want to execute.\n",pgmname);
  86.  
  87.     sprintf(sstr,"%smfx.c",pgmname); for(ii=0;ii<strlen(sstr);ii++){sstr[ii]=tolower(sstr[ii]);}
  88.     fp_xbc=fopen(sstr,"w"); if (fp_xbc==NULL){puts("ERR: can't write output file!");exit(1);}
  89.     sprintf(sstr,"%smfx.mta",pgmname); for(ii=0;ii<strlen(sstr);ii++){sstr[ii]=tolower(sstr[ii]);}
  90.     fp_xbm=fopen(sstr,"w"); if (fp_xbm==NULL){puts("ERR: can't write output file!");exit(1);}
  91.     sprintf(sstr,"%swdw.mta",pgmname); for(ii=0;ii<strlen(sstr);ii++){sstr[ii]=tolower(sstr[ii]);}
  92.     fp_wdw=fopen(sstr,"w"); if (fp_wdw==NULL){puts("ERR: can't write output file!");exit(1);}
  93.  
  94.     fprintf(fp_wdw,"Malloc(300); @start( (\"%s\") (\"bw\") );\n",pgmname);
  95.     fprintf(fp_wdw,"@%smfx();            %% Read MFX Group Definitions\n",pgmname);
  96.     }
  97.   | IFDEF         { puts("Found MFX Data Initialization..."); }
  98.   | ENDIF         {
  99.     puts("End of MFX Data Initialization");
  100.     write_c_files(c_var_name,pgmname);
  101.     }
  102.   | INT NAME ';'                  {
  103.     /*{{{  */
  104.     fprintf(fp_dmfx,"i( (\"%s\") 0 );\n",$2);
  105.     obj++;
  106.     fprintf(fp_dwdw,"o( $WDW,(\"%02dt\") S . 1 %d 8 1 Remark);bg( $WDW,(\"%02dt\") . (\"%s\") ); eg(); %% Description\n",obj,obj,obj,$2);
  107.     fprintf(fp_dwdw,"o( $WDW,(\"%02d\") I I 9 %d 8 1 Standard);bg( $WDW,(\"%02d\") . (ptr)MFX:$MFX.%s ); %% Integer Object\n",obj,obj,obj,$2);
  108.     fprintf(fp_dwdw,"  cn(epO $WDW,(\"%02d\") );",obj-1);
  109.     fprintf(fp_dwdw,"cn(edO $WDW,(\"%02d\") );eg(); \n",obj+1);
  110.     fprintf(fp_wmfx,"XbWMFX_PutInteger(&thestruct.%s,\"%s\");\n",$2,$2);
  111.     fprintf(fp_rmfx,"if(XbWMFX_GetInteger(&thestruct.%s)){goto error;}\n",$2);
  112.     printf("short %s\n",$2);
  113.     }
  114.     /*}}}  */
  115.   | INT NAME '[' NUMBER ']' ';'   {
  116.     /*{{{  */
  117.     { int ii, no;
  118.       no=atoi($4);
  119.       for (ii=0;ii<no;ii++){
  120.         fprintf(fp_dmfx,"i( (\"%s[%d]\") 0);\n",$2,ii);
  121.         fprintf(fp_wmfx,"XbWMFX_PutInteger(&thestruct.%s[%d],\"%s[%d]\");\n",$2,ii,$2,ii);
  122.         fprintf(fp_rmfx,"if(XbWMFX_GetInteger(&thestruct.%s[%d])){goto error;}\n",$2,ii);
  123.         }
  124.       printf("integer %s[%s]\n",$2,$4);
  125.       }
  126.     }
  127.     /*}}}  */
  128.   | INT NAME '[' NUMBER ']' '[' NUMBER ']' ';'   {
  129.     /*{{{  */
  130.     { int ii,jj, nox,noy;
  131.       nox=atoi($4);
  132.       noy=atoi($7);
  133.       for (ii=0;ii<nox;ii++){
  134.         for (jj=0;jj<noy;jj++){
  135.           fprintf(fp_dmfx,"i( (\"%s[%d][%d]\") 0);\n",$2,ii,jj);
  136.           fprintf(fp_wmfx,"XbWMFX_PutInteger(&thestruct.%s[%d][%d],\"%s[%d][%d]\");\n",$2,ii,jj,$2,ii,jj);
  137.           fprintf(fp_rmfx,"if(XbWMFX_GetInteger(&thestruct.%s[%d][%d])){goto error;}\n",$2,ii,jj);
  138.           }
  139.         }
  140.       printf("integer %s[%s][%s]\n",$2,$4,$7);
  141.       }
  142.     }
  143.     /*}}}  */
  144.   | INT NAME '[' NUMBER ']' '[' NUMBER ']' '[' NUMBER ']' ';'   {
  145.     /*{{{  */
  146.     { int ii,jj,kk, nox,noy,noz;
  147.       nox=atoi($4);
  148.       noy=atoi($7);
  149.       noz=atoi($10);
  150.       for (ii=0;ii<nox;ii++){
  151.         for (jj=0;jj<noy;jj++){
  152.           for (kk=0;kk<noz;kk++){
  153.             fprintf(fp_dmfx,"i( (\"%s[%d][%d][%d]\") 0);\n",$2,ii,jj,kk);
  154.             fprintf(fp_wmfx,"XbWMFX_PutInteger(&thestruct.%s[%d][%d][%d],\"%s[%d][%d][%d]\");\n",$2,ii,jj,kk,$2,ii,jj,kk);
  155.             fprintf(fp_rmfx,"if(XbWMFX_GetInteger(&thestruct.%s[%d][%d][%d])){goto error;}\n",$2,ii,jj,kk);
  156.             }
  157.           }
  158.         }
  159.       printf("integer %s[%s][%s][%s]\n",$2,$4,$7,$10);
  160.       }
  161.     }
  162.     /*}}}  */
  163.   | DOUBLE NAME ';'               {
  164.     /*{{{  */
  165.     fprintf(fp_dmfx,"d( (\"%s\") 0.0000001);\n",$2);
  166.     obj++;
  167.     fprintf(fp_dwdw,"o( $WDW,(\"%02dt\") S . 1 %d 8 1 Remark);bg( $WDW,(\"%02dt\") . (\"%s\") ); eg(); %% Description\n",obj,obj,obj,$2);
  168.     fprintf(fp_dwdw,"o( $WDW,(\"%02d\") S . 9 %d 15 1 Standard);  %% Double Float Object\n",obj,obj);
  169.     fprintf(fp_dwdw,"bg( $WDW,(\"%02d\") . (ptr)MFX:$MFX.%s );  %% Object Head\n",obj,$2);
  170.     fprintf(fp_dwdw,"  ff( (\"%%14.7f\") (\"\") 1 );\n          %% Object Body with Display Format\n");
  171.     fprintf(fp_dwdw,"  cn(epO $WDW,(\"%02d\") );",obj-1);
  172.     fprintf(fp_dwdw,"cn(edO $WDW,(\"%02d\") );eg(); \n",obj+1);
  173.     fprintf(fp_wmfx,"XbWMFX_PutDouble(&thestruct.%s,\"%s\");\n",$2,$2);
  174.     fprintf(fp_rmfx,"if(XbWMFX_GetDouble(&thestruct.%s)){goto error;}\n",$2);
  175.     printf("double %s\n",$2);
  176.     }
  177.     /*}}}  */
  178.   | DOUBLE NAME '[' NUMBER ']' ';'   {
  179.     /*{{{  */
  180.     { int ii, no;
  181.       no=atoi($4);
  182.       for (ii=0;ii<no;ii++){
  183.         fprintf(fp_dmfx,"d( (\"%s[%d]\") 0.0000001 );\n",$2,ii);
  184.         fprintf(fp_wmfx,"XbWMFX_PutDouble(&thestruct.%s[%d],\"%s[%d]\");\n",$2,ii,$2,ii);
  185.         fprintf(fp_rmfx,"if(XbWMFX_GetDouble(&thestruct.%s[%d])){goto error;}\n",$2,ii);
  186.         }
  187.       printf("double %s[%s]\n",$2,$4);
  188.       }
  189.     }
  190.     /*}}}  */
  191.   | DOUBLE NAME '[' NUMBER ']' '[' NUMBER ']' ';'   {
  192.     /*{{{  */
  193.     { int ii,jj, nox,noy;
  194.       nox=atoi($4);
  195.       noy=atoi($7);
  196.       for (ii=0;ii<nox;ii++){
  197.         for (jj=0;jj<noy;jj++){
  198.           fprintf(fp_dmfx,"d( (\"%s[%d][%d]\") 0.0000001 );\n",$2,ii,jj);
  199.           fprintf(fp_wmfx,"XbWMFX_PutDouble(&thestruct.%s[%d][%d],\"%s[%d][%d]\");\n",$2,ii,jj,$2,ii,jj);
  200.           fprintf(fp_rmfx,"if(XbWMFX_GetDouble(&thestruct.%s[%d][%d])){goto error;}\n",$2,ii,jj);
  201.           }
  202.         }
  203.       printf("double %s[%s][%s]\n",$2,$4,$7);
  204.       }
  205.     }
  206.     /*}}}  */
  207.   | DOUBLE NAME '[' NUMBER ']' '[' NUMBER ']' '[' NUMBER ']' ';'   {
  208.     /*{{{  */
  209.     { int ii,jj,kk, nox,noy,noz;
  210.       nox=atoi($4);
  211.       noy=atoi($7);
  212.       noz=atoi($10);
  213.       for (ii=0;ii<nox;ii++){
  214.         for (jj=0;jj<noy;jj++){
  215.           for (kk=0;kk<noz;kk++){
  216.             fprintf(fp_dmfx,"d( (\"%s[%d][%d][%d]\") 0.0000001 );\n",$2,ii,jj,kk);
  217.             fprintf(fp_wmfx,"XbWMFX_PutDouble(&thestruct.%s[%d][%d][%d],\"%s[%d][%d][%d]\");\n",$2,ii,jj,kk,$2,ii,jj,kk);
  218.             fprintf(fp_rmfx,"if(XbWMFX_GetDouble(&thestruct.%s[%d][%d][%d])){goto error;}\n",$2,ii,jj,kk);
  219.             }
  220.           }
  221.         }
  222.       printf("double %s[%s][%s][%s]\n",$2,$4,$7,$10);
  223.       }
  224.     }
  225.     /*}}}  */
  226.   | STRING NAME '[' NUMBER ']' ';'{
  227.     /*{{{  */
  228.     fprintf(fp_dmfx,"s( (\"%s\") %s (\" \") );\n",$2,$4);
  229.     obj++;
  230.     fprintf(fp_dwdw,"o( $WDW,(\"%02dt\") S . 1 %d 8 1 Remark);bg( $WDW,(\"%02dt\") . (\"%s\") ); eg(); %% Description\n",obj,obj,obj,$2);
  231.     fprintf(fp_dwdw,"o( $WDW,(\"%02d\") S S 9 %d 40 1 Standard);bg( $WDW,(\"%02d\") . (ptr)MFX:$MFX.%s );       %% String Object\n",obj,obj,obj,$2);
  232.     fprintf(fp_dwdw,"  cn(epO $WDW,(\"%02d\") );",obj-1);
  233.     fprintf(fp_dwdw,"cn(edO $WDW,(\"%02d\") );eg(); \n",obj+1);
  234.     fprintf(fp_wmfx,"XbWMFX_PutString(thestruct.%s,\"%s\");\n",$2,$2);
  235.     fprintf(fp_rmfx,"if(XbWMFX_GetString(thestruct.%s)){goto error;}\n",$2);
  236.     printf("string %s\n",$2);
  237.     }
  238.     /*}}}  */
  239.   | STRING NAME '[' NUMBER ']' '[' NUMBER ']' ';'   {
  240.     /*{{{  */
  241.     { int ii, nox;
  242.       nox=atoi($4);
  243.       for (ii=0;ii<nox;ii++){
  244.         fprintf(fp_dmfx,"s( (\"%s[%d]\") %s (\" \") );\n",$2,ii,$4);
  245.         fprintf(fp_wmfx,"XbWMFX_PutString(&thestruct.%s[%d][0],\"%s[%d]\");\n",$2,ii,$2,ii);
  246.         fprintf(fp_rmfx,"if(XbWMFX_GetString(&thestruct.%s[%d][0])){goto error;}\n",$2,ii);
  247.         }
  248.       printf("string %s[%s]\n",$2,$4);
  249.       }
  250.     }
  251.     /*}}}  */
  252.   | SHORT NAME ';'                {
  253.     /*{{{  */
  254.     fprintf(fp_dmfx,"i( (\"%s\") 0 );\n",$2);
  255.     obj++;
  256.     fprintf(fp_dwdw,"o( $WDW,(\"%02dt\") S . 1 %d 8 1 Remark);bg( $WDW,(\"%02dt\") . (\"%s\") ); eg(); %% Description\n",obj,obj,obj,$2);
  257.     fprintf(fp_dwdw,"o( $WDW,(\"%02d\") I I 9 %d 8 1 Standard);bg( $WDW,(\"%02d\") . (ptr)MFX:$MFX.%s );  %% Integer Object\n",obj,obj,obj,$2);
  258.     fprintf(fp_dwdw,"  cn(epO $WDW,(\"%02d\") );",obj-1);
  259.     fprintf(fp_dwdw,"cn(edO $WDW,(\"%02d\") );eg(); \n",obj+1);
  260.     fprintf(fp_wmfx,"XbWMFX_PutShort(&thestruct.%s,\"%s\");\n",$2,$2);
  261.     fprintf(fp_rmfx,"if(XbWMFX_GetShort(&thestruct.%s)){goto error;}\n",$2);
  262.     printf("short %s\n",$2);
  263.     }
  264.     /*}}}  */
  265.   | SHORT NAME '[' NUMBER ']' ';'   {
  266.     /*{{{  */
  267.     { int ii, no;
  268.       no=atoi($4);
  269.       for (ii=0;ii<no;ii++){
  270.         fprintf(fp_dmfx,"i( (\"%s[%d]\") 0);\n",$2,ii);
  271.         fprintf(fp_wmfx,"XbWMFX_PutShort(&thestruct.%s[%d],\"%s[%d]\");\n",$2,ii,$2,ii);
  272.         fprintf(fp_rmfx,"if(XbWMFX_GetShort(&thestruct.%s[%d])){goto error;}\n",$2,ii);
  273.         }
  274.       printf("short %s[%s]\n",$2,$4);
  275.       }
  276.     }
  277.     /*}}}  */
  278.   | SHORT NAME '[' NUMBER ']' '[' NUMBER ']' ';'   {
  279.     /*{{{  */
  280.     { int ii,jj, nox,noy;
  281.       nox=atoi($4);
  282.       noy=atoi($7);
  283.       for (ii=0;ii<nox;ii++){
  284.         for (jj=0;jj<noy;jj++){
  285.           fprintf(fp_dmfx,"i( (\"%s[%d][%d]\") 0);\n",$2,ii,jj);
  286.           fprintf(fp_wmfx,"XbWMFX_PutShort(&thestruct.%s[%d][%d],\"%s[%d][%d]\");\n",$2,ii,jj,$2,ii,jj);
  287.           fprintf(fp_rmfx,"if(XbWMFX_GetShort(&thestruct.%s[%d][%d])){goto error;}\n",$2,ii,jj);
  288.           }
  289.         }
  290.       printf("short %s[%s][%s]\n",$2,$4,$7);
  291.       }
  292.     }
  293.     /*}}}  */
  294.   | SHORT NAME '[' NUMBER ']' '[' NUMBER ']' '[' NUMBER ']' ';'   {
  295.     /*{{{  */
  296.     { int ii,jj,kk, nox,noy,noz;
  297.       nox=atoi($4);
  298.       noy=atoi($7);
  299.       noz=atoi($10);
  300.       for (ii=0;ii<nox;ii++){
  301.         for (jj=0;jj<noy;jj++){
  302.           for (kk=0;kk<noz;kk++){
  303.             fprintf(fp_dmfx,"i( (\"%s[%d][%d][%d]\") 0);\n",$2,ii,jj,kk);
  304.             fprintf(fp_wmfx,"XbWMFX_PutShort(&thestruct.%s[%d][%d][%d],\"%s[%d][%d][%d]\");\n",$2,ii,jj,kk,$2,ii,jj,kk);
  305.             fprintf(fp_rmfx,"if(XbWMFX_GetShort(&thestruct.%s[%d][%d][%d])){goto error;}\n",$2,ii,jj,kk);
  306.             }
  307.           }
  308.         }
  309.       printf("short %s[%s][%s][%s]\n",$2,$4,$7,$10);
  310.       }
  311.     }
  312.     /*}}}  */
  313.   ;
  314. %%
  315.  
  316. int put_lval_number(char *sst){strcpy(yylval.sstr,sst);      return(NUMBER); }
  317. int put_lval_name(char *sst){  strcpy(yylval.sstr,sst);      return(NAME);   }
  318. int put_lval_integer(void){    strcpy(yylval.sstr,"int");    return(INT);    }
  319. int put_lval_double(void){     strcpy(yylval.sstr,"double"); return(DOUBLE); }
  320. int put_lval_string(void){     strcpy(yylval.sstr,"char");   return(STRING); }
  321. int put_lval_short(void){      strcpy(yylval.sstr,"short");  return(SHORT);  }
  322. int put_lval_typedef(void){    strcpy(yylval.sstr,"typedef");return(TYPEDEF);}
  323. int put_lval_struct(void){     strcpy(yylval.sstr,"struct"); return(STRUCT); }
  324. int put_lval_extern(void){     strcpy(yylval.sstr,"extern"); return(EXTERN); }
  325. int put_lval_define(void){     strcpy(yylval.sstr,"define"); return(DEFINE); }
  326. int put_lval_ifdef(void){      strcpy(yylval.sstr,"ifdef");  return(IFDEF);  }
  327. int put_lval_endif(void){      strcpy(yylval.sstr,"endif");  return(ENDIF);  }
  328. int put_lval_pgmname(void){    strcpy(yylval.sstr,"pgmname");return(PGMNAME);}
  329. int put_lval_mfxinit(void){    strcpy(yylval.sstr,"mfxinit");return(MFXINIT);}
  330.  
  331.  
  332. void create_c_files(void){
  333.   c_var_name[0]=0;
  334.   obj=4;
  335.   fp_wmfx=fopen("makemfx.wmfx","w"); if (fp_wmfx==NULL){puts("ERR: can't write scratch file!");exit(1);}
  336.   fp_rmfx=fopen("makemfx.rmfx","w"); if (fp_rmfx==NULL){puts("ERR: can't write scratch file!");exit(1);}
  337.   fp_dmfx=fopen("makemfx.dmfx","w"); if (fp_dmfx==NULL){puts("ERR: can't write scratch file!");exit(1);}
  338.   fp_dwdw=fopen("makemfx.dwdw","w"); if (fp_dwdw==NULL){puts("ERR: can't write scratch file!");exit(1);}
  339.   }
  340.  
  341. int write_c_files(char *s, char *pgm){
  342.   char sstr[100];
  343.   int ii;
  344.  
  345.   fclose(fp_dmfx);
  346.   fclose(fp_rmfx);
  347.   fclose(fp_wmfx);
  348.   fclose(fp_dwdw);
  349.  
  350.   system("cp /xw/xbmfx/* .");
  351.   fprintf(fp_xbc,"/*  XbW MetaFile eXchange (Interface to Applications): XBMFX  */\n");
  352.  
  353.   if (!struct_defined){
  354.     struct_defined = 1;
  355.     fprintf(fp_xbc,"\n#ifdef ALREADY_DEFINED_MFX_%s /* Schon #defined ? */\n",s);
  356.     fprintf(fp_xbc,"\n#else \n");
  357.     fprintf(fp_xbc,"\n#define ALREADY_DEFINED_MFX_%s 1 \n",s);
  358.     fprintf(fp_xbc,"\n#ifndef ProgramName /* Extra Module */\n");
  359.     fprintf(fp_xbc,"#include <stdlib.h>\n");
  360.     fprintf(fp_xbc,"#include <stdio.h>\n");
  361.     fprintf(fp_xbc,"#include <string.h>\n");
  362.     fprintf(fp_xbc,"#define MFX_INIT 1\n");
  363.     fprintf(fp_xbc,"#include \"xbmfx.h\"\n");
  364.     fprintf(fp_xbc,"#include \"%smfx.h\"\n",pgm);
  365.     fprintf(fp_xbc,"\n#endif /*ProgramName*/\n");
  366.     }
  367.  
  368.   fprintf(fp_xbc,"\n#ifdef thestruct\n");
  369.   fprintf(fp_xbc,"#undef thestruct\n");
  370.   fprintf(fp_xbc,"#endif\n");
  371.  
  372.   if (!c_var_name[0]){
  373.     fprintf(fp_xbc,"#define thestruct MFX_%s\n\n",s);
  374.     fprintf(fp_xbc,"%s MFX_%s;\n\n",s,s);
  375.   } else {
  376.     fprintf(fp_xbc,"#define thestruct %s\n\n",c_var_name);
  377.     }
  378.  
  379.   fprintf(fp_xbc,"int WriteMFXGroup_%s(char*filename, char*dataset, char *mode){\n",c_var_name);
  380.   /*{{{  */
  381.   fprintf(fp_xbc,"  if (filename == NULL) { filename = \"%s.mfx\"; } \n",c_var_name);
  382.   fprintf(fp_xbc,"  if (dataset == NULL) { dataset = \"%s\"; }\n",s);
  383.   fprintf(fp_xbc,"  if (mode == NULL) { mode = \"w\"; }\n");
  384.   fprintf(fp_xbc,"  if (XbWMFX_WriteSet(filename,dataset,mode)) {\n");
  385.   fprintf(fp_xbc,"    return(1);\n");
  386.   fprintf(fp_xbc,"    }\n");
  387.   {
  388.     char li[1000];
  389.     fp_wmfx=fopen("makemfx.wmfx","r");
  390.     if (fp_wmfx==NULL){puts("ERR: can't read scratch file!");exit(1);}
  391.     while(!feof(fp_wmfx)){
  392.       if (fgets(li,1000,fp_wmfx)){
  393.         fputs(li,fp_xbc);
  394.         }
  395.       }
  396.     }
  397.   
  398.   fclose(fp_wmfx);
  399.   unlink("makemfx.wmfx");
  400.   
  401.   fprintf(fp_xbc,"  XbWMFX_WriteEnd();\n");
  402.   fprintf(fp_xbc,"  XbWMFX_CloseSet();\n");
  403.   fprintf(fp_xbc,"  return(0);\n");
  404.   fprintf(fp_xbc,"  }\n\n");
  405.   
  406.   /*}}}  */
  407.   fprintf(fp_xbc,"int ReadMFXGroup_%s(char*filename, char*dataset){\n",c_var_name);
  408.   /*{{{  */
  409.   fprintf(fp_xbc,"  if (filename == NULL) { filename = \"%s.mfx\"; } \n",c_var_name);
  410.   fprintf(fp_xbc,"  if (dataset == NULL) { dataset = \"%s\"; }\n",s);
  411.   fprintf(fp_xbc,"  if (XbWMFX_ReadSet(filename,dataset)) {\n");
  412.   fprintf(fp_xbc,"    puts(\"ERR on opening MFX file; I will now try to append\");\n");
  413.   fprintf(fp_xbc,"    ropenerr:;\n");
  414.   fprintf(fp_xbc,"    printf(\"a working MFX Group %%s to the end of file %%s...\\n\",dataset,filename);\n");
  415.   fprintf(fp_xbc,"    if (!WriteMFXGroup_%s(filename,dataset,\"a\")){\n",c_var_name);
  416.   fprintf(fp_xbc,"      puts(\"...done. Exiting with error code.\");\n");
  417.   fprintf(fp_xbc,"      printf(\"The end of file %%s should now be readable. Please check its contents!\\n\",filename);\n");
  418.   fprintf(fp_xbc,"      printf(\"If %%s did not exist until now, don't get crazy :)\\n\",filename);\n");
  419.   fprintf(fp_xbc,"      return(1);\n");
  420.   fprintf(fp_xbc,"      }\n");
  421.   fprintf(fp_xbc,"    else {\n");
  422.   fprintf(fp_xbc,"      puts(\"...did not work. Exiting with error code.\");\n");
  423.   fprintf(fp_xbc,"      printf(\"I must now overwrite your file %%s, sorry. Please check its contents!\\n\",filename);\n");
  424.   fprintf(fp_xbc,"      WriteMFXGroup_%s(filename,dataset,\"w\");\n",c_var_name);
  425.   fprintf(fp_xbc,"      printf(\"If %%s did not exist until now, don't get crazy :)\\n\",filename);\n");
  426.   fprintf(fp_xbc,"      return(1);\n");
  427.   fprintf(fp_xbc,"      }\n");
  428.   fprintf(fp_xbc,"    }\n");
  429.   {
  430.     char li[1000];
  431.     fp_rmfx=fopen("makemfx.rmfx","r");
  432.     if (fp_rmfx==NULL){puts("ERR: can't read scratch file!");exit(1);}
  433.     while(!feof(fp_rmfx)){
  434.       if (fgets(li,1000,fp_rmfx)>0){
  435.         fputs(li,fp_xbc);
  436.         }
  437.       }
  438.     }
  439.   
  440.   fprintf(fp_xbc,"  XbWMFX_CloseSet();\n");
  441.   fprintf(fp_xbc,"  return(0);\n");
  442.   fprintf(fp_xbc,"error:;\n");
  443.   fprintf(fp_xbc,"  printf(\"Error while reading MFX Group %s\\n\");",c_var_name);
  444.   fprintf(fp_xbc,"  XbWMFX_CloseSet();\n");
  445.   fprintf(fp_xbc,"  puts(\"I will now try to append\");\n");
  446.   fprintf(fp_xbc,"  goto ropenerr;\n");
  447.   fprintf(fp_xbc,"  }\n\n\n");
  448.   
  449.   fclose(fp_rmfx);
  450.   unlink("makemfx.rmfx");
  451.   
  452.   /*}}}  */
  453.   fprintf(fp_xbc,"\n#undef thestruct\n");
  454.  
  455.   fprintf(fp_xbm," %% XbW MFX Group %s\n",s);
  456.   /*{{{  */
  457.   sprintf(sstr,"%s",s); for(ii=0;ii<strlen(sstr);ii++){sstr[ii]=tolower(sstr[ii]);}
  458.   fprintf(fp_xbm,"@mfxgroup/begin( %s (\"%s.mfx\") (\"xbwmfx.\") );\n",s,sstr);
  459.   {
  460.     char li[1000];
  461.     fp_dmfx=fopen("makemfx.dmfx","r");
  462.     if (fp_dmfx==NULL){puts("ERR: can't read scratch file!");exit(1);}
  463.     while(!feof(fp_dmfx)){
  464.       if(fgets(li,1000,fp_dmfx)){
  465.         fputs(li,fp_xbm);
  466.         }
  467.       }
  468.     }
  469.   fclose(fp_dmfx);
  470.   unlink("makemfx.dmfx");
  471.   
  472.   fprintf(fp_xbm,"@mfxgroup/end();\n\n");
  473.   
  474.   /*}}}  */
  475.   fprintf(fp_trl,"MFXGroup( Read %s );\n",s);
  476.  
  477.   /* write window */
  478.   /*{{{  */
  479.   {
  480.     char wdwname[4];
  481.     char li[1000];
  482.     wdwnr++;
  483.     sprintf(wdwname,"WD%02d",wdwnr);
  484.     fprintf(fp_wdw," %% XbW Window definition for MFX Group %s\n",c_var_name);
  485.     fprintf(fp_wdw,"wdw( %s %d %d 60 40 StandardWDW );     %% Get a Window\n",wdwname,wdwnr,wdwnr);
  486.     fprintf(fp_wdw,"@window/gimmicks( (\"%s\") (\" Program '%s' Test-Window '%s' (P) by XbW\") );  %% Get some buttons\n",wdwname,pgmname,wdwname);
  487.     fprintf(fp_wdw,"$MFX:=%s;   %% Set MFX Group Name\n",c_var_name);
  488.     fprintf(fp_wdw,"$WDW:=%s;   %% Set Window Name\n",wdwname);
  489.   
  490.     fprintf(fp_wdw,"o( $WDW,(\"01\") S . 1 3 9 1 Secure );   %% This Object Exits XBW\n");
  491.     fprintf(fp_wdw,"bg( $WDW,(\"01\") . (\"Exit XbW\") );\n");
  492.     fprintf(fp_wdw,"  cn( raK (\"@stop();\") );               %% Macro to Exit XbW\n");
  493.     fprintf(fp_wdw,"  eg();\n");
  494.   
  495.     fprintf(fp_wdw,"o( $WDW,(\"02\") S T 11 3 30 1 Secure );   %% This Object starts the User Program\n");
  496.     fprintf(fp_wdw,"bg( $WDW,(\"02\") . (\" Start Program %s\") );\n",pgmname);
  497.     fprintf(fp_wdw,"  tk( (\"\") (\"%s\") );             %% Program name\n",pgmname);
  498.     fprintf(fp_wdw,"  cn( wbX (\"%s\") );                %% Write MFX Group Before Start\n",c_var_name);
  499.     fprintf(fp_wdw,"  cn( raX (\"%s\") );                %% Read MFX Group after End\n",c_var_name);
  500.     fprintf(fp_wdw,"  eg();\n");
  501.   
  502.     fp_dwdw=fopen("makemfx.dwdw","r");
  503.     if (fp_dwdw==NULL){puts("ERR: can't read scratch file!");exit(1);}
  504.     while(!feof(fp_dwdw)){
  505.       if(fgets(li,1000,fp_dwdw)){
  506.         fputs(li,fp_wdw);
  507.         }
  508.       }
  509.     }
  510.   fclose(fp_dwdw);
  511.   unlink("makemfx.dwdw");
  512.   
  513.   /*}}}  */
  514.   return(0);
  515.   }
  516.  
  517. int main(int argc, char **argv){
  518.   extern FILE *yyin;
  519.  
  520.   yyin=NULL;
  521.   if (argc>0){     yyin = fopen(argv[1],"r"); }
  522.   if (yyin==NULL){ yyin = stdin; }
  523.  
  524. /*  yydebug = 1; */
  525.  
  526.   fp_trl=fopen("makemfx.emfx","w"); if (fp_trl==NULL){puts("ERR: can't write scratch file!");exit(1);}
  527.  
  528.   yyparse();
  529.  
  530.   fclose(fp_trl);
  531.   {
  532.     char li[1000];
  533.     fp_trl=fopen("makemfx.emfx","r");
  534.     if (fp_trl==NULL){puts("ERR: can't read scratch file!");exit(1);}
  535.     while(!feof(fp_trl)){
  536.       if(fgets(li,1000,fp_trl)){
  537.         fputs(li,fp_wdw);
  538.         }
  539.       }
  540.     }
  541.  
  542.   fprintf(fp_wdw,"SelectWdw( (\"W001\") );\n");
  543.  
  544.   fclose(fp_trl);
  545.   unlink("makemfx.emfx");
  546.  
  547.   fprintf(fp_wdw,"End();\n\n");
  548.  
  549.   fprintf(fp_xbm,"End();\n\n");
  550.   fprintf(fp_xbc,"\n#endif /* ALREADY_DEFINED_MFX_... */\n");
  551.   fclose(fp_xbc);
  552.   fclose(fp_xbm);
  553.   fclose(fp_wdw);
  554.  
  555.   return(0);
  556.   }
  557.  
  558.